package cn.itcast.core.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RetryRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @auther :hyh
 * @desc :
 * @date :2019/5/8
 */
@Configuration
public class ConfigBean {

    @Bean
    @LoadBalanced  //启动负载均衡
    public RestTemplate restTemplate() {

        return new RestTemplate();
    }

    @Bean
    public IRule myIRule() {
//        return new RandomRule();  //随机访问
        return new RetryRule();    //默认随机获取，当某个服务宕机后，某个时间内会重试。
    }
}
